package org.budo.graph.service.util;

import java.util.Map;

import org.budo.graph.Constant;
import org.budo.support.freemarker.FreemarkerUtil;
import org.budo.support.lang.util.MapUtil;
import org.budo.support.lang.util.StringUtil;
import org.budo.support.lang.util.SystemUtil;
import org.budo.support.spring.io.util.ResourceUtil;

import com.alibaba.druid.support.json.JSONUtils;

/**
 * @author limingwei
 * @date 2016年6月14日 下午8:37:54
 */
public class SystemPropertyUtil {
    private static final String DUBBO_DRUID_FM_SYSTEM_INFO_HTM = Constant.GRAPH_TEMPLATE_PATH + "/system-property.htm";

    public static String writeSystemPropertyResponse(String url) {
        Map<String, Object> map = MapUtil.stringObjectMap("properties", SystemUtil.getProperties(), //
                "env", SystemUtil.getEnv());

        if (StringUtil.startsWith(url, "/system-property.json")) {
            return JSONUtils.toJSONString(map);
        }

        String inputString = ResourceUtil.classPathResourceInputStreamToString(DUBBO_DRUID_FM_SYSTEM_INFO_HTM);
        return FreemarkerUtil.freemarkerRender(inputString, map);
    }
}